/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entities;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

/**
 *
 * @author Maciek
 */
public class DateConverter implements Converter {

    public Date getAsObject(FacesContext context, UIComponent component, String value) {
        Date date = null;

        DateFormat formatter ;
        formatter = new SimpleDateFormat("yyyy-MM-dd");
        try {
            date = (Date) formatter.parse(value);
        } catch (ParseException ex) {
            Logger.getLogger(DateConverter.class.getName()).log(Level.SEVERE, null, ex);
        }

        return date;
    }

    public String getAsString(FacesContext context, UIComponent component, Object value) {
         String name = ((Date) value).toString();
         return name;
    }

}
